package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.dto.Activitydto;
import com.qk.entity.Activity;
import com.qk.mapper.ActivityMapper;
import com.qk.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityServiceimpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public PageResult<Activity> listAll(Activitydto activitydto) {
        PageHelper.startPage(activitydto.getPage(),activitydto.getPageSize());
        List<Activity> activityList = activityMapper.listAll(activitydto);
        Page<Activity> page = (Page<Activity>) activityList;
        return  new PageResult<>(page.getTotal(),page.getResult());
    }

    @Override
    public void delete(Integer id) {
        activityMapper.delete(id);
    }

    @Override
    public void save(Activity activity) {
        activity.setCreateTime(LocalDateTime.now());
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.save(activity);

    }

    @Override
    public Activity get(Integer id) {
        Activity activity = activityMapper.getid(id);
        return activity;
    }

    @Override
    public void update(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.update(activity);
    }

    @Override
    public List<Activity> listByType(Integer type) {
        List<Activity> activityList = activityMapper.listByType(type);
        return activityList;
    }

    @Override
    public List<Activity> listByTypeAll() {
        List<Activity> activityList = activityMapper.listByTypeAll();
        return activityList;
    }
}
